package cn.restcloud.example.controller.org;

import java.util.ArrayList;
import java.util.List;

import cn.restcloud.framework.core.annotation.bean.BeanConfig;
import cn.restcloud.framework.core.annotation.bean.BeanType;
import cn.restcloud.framework.core.util.PrintUtil;
import cn.restcloud.framework.org.base.IUserContextInitEvent;
import cn.restcloud.framework.org.model.P_OrgPersonContext;


@BeanConfig(appId = "example",beanId = "UserContextInitEvent_Test",beanName = "用户数据初始化时执行",beanType = BeanType.SERVICE,autowired = true,singleton = true,hotMode = true)
public class UserContextInitTest implements IUserContextInitEvent {
	//UserContextInitEvent 的beanId不可以修改
	
	@Override
	public void initUserContext(P_OrgPersonContext personContext, String tokenProps) throws Exception {
		//可以通过personContext来动态设定用户的权限及角色
		List<String> permissionIds=new ArrayList<String>();
		List<String> rolesCode=new ArrayList<String>();
		permissionIds.add("core.superadmin");
		permissionIds.add("core.appdesigner");
		rolesCode.add("superadmin");
		rolesCode.add("appdesigner");
		
		personContext.setPermissionId(permissionIds);
		personContext.setRolesCode(rolesCode);
		PrintUtil.o(personContext.getUserId()+","+personContext.getPermissionId());
		PrintUtil.o(tokenProps);
	}

}
